package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Commodity;
import cn.wolfcode.trip.base.query.CommodityQueryObject;
import cn.wolfcode.trip.base.service.ICommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/commoditys")
public class CommodityController {
    @Autowired
    private ICommodityService commodityService;

    @GetMapping("/{status}")
    public Object getHot(CommodityQueryObject qo){
        return commodityService.query(qo);
    }
    @GetMapping("/{id}/details")
    public Object getOne(@PathVariable Long id){
        return commodityService.getOne(id);
    }
    @GetMapping("/types")
    public Object types(){
        List<Commodity> types = commodityService.types();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list", types);
        return map;
    }
    @GetMapping("/{type}/types")
    public Object types(CommodityQueryObject qo){
        return commodityService.query(qo);
    }
}
